 <template>
  <el-dialog
    title="提示"
    :visible="dialogVisible"
    width="60%"
    @close="handleClose"
  >
    <el-row>
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>
          【题型】：{{ Titledetil.questionType | questionTypefilter() }}
        </div></el-col>
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>【编号】：{{ Titledetil.number }}</div></el-col
      >
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>
          【难度】：{{ Titledetil.difficulty | difficultyfilter() }}
        </div></el-col
      >
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>【标签】：{{ Titledetil.tags }}</div></el-col
      >
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>【学科】：{{ Titledetil.subjectName }}</div></el-col
      >
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>【目录】：{{ Titledetil.directoryName }}</div></el-col
      >
      <el-col :span="6" style="margin-bottom: 20px"
        ><div>【方向】：{{ Titledetil.direction }}</div></el-col
      >
    </el-row>
    <hr />
    <div style="margin-bottom: 17px">【题干】：</div>
    <div style="margin-bottom: 17px; color: blue">
      {{ this.Titledetil.question | tellfilter() }}
    </div>
    <div>
      <div
        v-if="this.Titledetil.questionType === '1'"
        style="margin-bottom: 17px"
      >
        单选题选项 (以下选中的答案为正确答案)
      </div>
      <div
        v-if="this.Titledetil.questionType === '2'"
        style="margin-bottom: 17px"
      >
        多选题选项 (以下选中的答案为正确答案)
      </div>
      <div
        v-for="item in Titledetil.options"
        :key="item.code"
        style="padding: 8px 0"
      >
        <el-radio
          v-if="Titledetil.questionType === '1'"
          :value="item.isRight"
          :label="1"
          >{{ item.title }}</el-radio
        >
        <el-checkbox
          v-if="Titledetil.questionType === '2'"
          :value="item.isRight ? true : false"
          >{{ item.title }}</el-checkbox
        >
      </div>
    </div>
    <hr />
    <div style="padding: 12px 0">
      【参考答案】：<el-button
        type="danger"
        @click="preivewVideo"
        style="margin-bottom: 24px"
        >视频答案预览</el-button
      >
      <!-- 视频播放器 -->
      <div v-show="play">
        <video ref="video" :src="Titledetil.videoURL" controls
        style="width: 400px;"
        ></video>
      </div>
    </div>
    <hr />
    <div
      style="padding: 14px 0"
      v-html="'【答案解析】：' + Titledetil.answer"
    ></div>
    <hr />
    <div
      style="padding: 14px 0"
      v-html="'【题目备注】：' + Titledetil.remarks"
    ></div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleClose">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'questionsPreview',
  data () {
    return {
      play: false
    }
  },

  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    titleId: {
      type: Number,
      required: true
    },
    Titledetil: {
      type: Object,
      required: true
    },
    options: {
      type: Array,
      required: true
    }
  },
  filters: {
    tellfilter (v) {
      if (typeof v === 'string') {
        return v.replace(/<\/?.+?>/g, '')
      }
    },
    questionTypefilter (v) {
      if (v === '1') {
        return '单选'
      } else if (v === '2') {
        return '多选'
      } else if (v === '3') {
        return '简答'
      }
    },
    difficultyfilter (v) {
      if (v === '1') {
        return '简单'
      } else if (v === '2') {
        return '一般'
      } else if (v === '3') {
        return '困难'
      }
    }
  },
  methods: {
    preivewVideo () {
      this.play = !this.play
      this.$refs.video.play()
    },
    handleClose () {
      this.$emit('update:dialogVisible', false)
      this.$refs.video.pause()
      this.play = false
    }
  }
}
</script>

<style>
</style>
